<?php session_start(); 
if ( $_SESSION["level"] == null ) header("location:login.php");
?>
<!DOCTYPE html>
<html>
 <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <link rel="shortcut icon" href="./files/img/favicon.ico">
  <title>IAD - Euromedica</title>

  <link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/themes/redmond/jquery-ui.css" rel="Stylesheet" />	
  <script type="text/javascript" src="./files/jquery-1.6.4.js"></script>
  <script type="text/javascript" src="./files/jquery-ui/js/jquery-ui-1.8.16.custom.min.js"></script>
  <script type="text/javascript" src="./files/padolsey-jQuery-Plugins-01abd79/sortElements/jquery.sortElements.js"></script>

  <style type="text/css">
    @import "style2.css";
  </style>

  <script type="text/javascript" src="./scripts.js"></script>
</head>
 <?php 
   include 'sql.php';
   $contact = $_GET['contact'];
   $filter = $_GET['filter'];
   $unit = $_GET['unit'];
 ?>

<body>

<div id="access">
  <?php showRightPanel(); ?>
</div> <!--End of access-->

  <!--
  Start Header Area
  -->
<div id="header">
</div><!-- End of HEADER -->

<div id="ribbon">
  <table>
    <tr>

    </tr>
  </table>
</div><!--End of ribbon-->

 <!--
  Start Left Panel Area
  -->
  <?php showLeftPanel($_SESSION['level'], $_SESSION['user']); ?>
    <!--
    End of Left_panel
    -->

 <!--
  Start Container Area
  -->
 <div id="container">
  <div id="content"><!-- Content Area-->
	<table id="team" class="requests_table">
	 <!-- <tr><td></td><td></td>-->
	    <td><?php showLogo($unit); ?></td>
	    <td><table><?php showUnitInfo($unit); ?></table></td>
	  <!--</tr><tr><td></td></tr><tr><td></td></tr>--></table>
	<table id="team" class="requests_table">
	 <form name="contacts" action="confirmation.php" method="post">
	  <?php
	      if ($contact == "clinics" || $contact == "central" || $contact == "hotels" || $contact == "embassies" || $contact == "misc") { 
		showContacts($contact, $unit, $filter);
	      } //end of if
	      else {
		print("<h1>I said NO</h1>");
	      }
	      if ($_SESSION['level'] == "admin"){
	    ?>
 	      <input type="button" class="add_btn" name="add" value="Add" style="margin: 0 auto;">
<!-- 	      <input type="button" id="check" name="Check" value="Delete All" style="margin: 0 auto;"<?php if( $count == 0){?> disabled="disabled"<?php }//end of if ?> > -->
	    <div id="dialog-confirm" hidden>
	      <form id="add_con">
	      <fieldset>
		<label for="Name">Ονοματεπώνυμο:</label><br>
		<input type="text" name="name" id="con_name" class="text ui-widget-content ui-corner-all"></input><br>
		<label for="tel1">Τηλέφωνο 1:</label><br>
		<input type="text" name="tel1" id="tel1" class="text ui-widget-content ui-corner-all"></input><br>
		<label for="tel2">Τηλέφωνο 2:</label><br>
		<input type="text" name="tel2" id="tel2" class="text ui-widget-content ui-corner-all"></input><br>
		<label for="cell">Κινητό:</label><br>
		<input type="text" name="cell" id="cell" class="text ui-widget-content ui-corner-all"></input><br>
		<label for="email">Email:</label><br>
		<input type="text" name="email" id="email" class="text ui-widget-content ui-corner-all"></input><br>
		<label for="locate">Τοποθεσία:</label><br>
		  <select id="location1" name="location1">
		    <option value="" label="">Επιλογή...</option>
		    <option value="clinics" label="">Κλινικές</option>
		    <option value="central" label="">Κεντρικά</option>
		    <option value="hotels" label="">Ξενοδοχεία</option>
		    <option value="embassies" label="">Πρεσβείες</option>
		    <option value="misc" label="">Διάφορα</option>
		  </select>
		<br>
		<label for="unit">Ξενοδοχείο/Μονάδα:</label><br>
		  <select id="unit" name="unit">
		    <option value="" label="">Επιλογή...</option>
		    <option value="arogi" label="">Αρωγή</option>
		    <option value="geniki" label="">Γενική</option>
		    <option value="kentriki" label="">Κεντρική</option>
		    <option value="kianous" label="">Κυανούς Σταυρός</option>
		    <option value="zoodochos" label="">Ζωοδόχος Πηγή</option>
		    <option value="arogi_larisa" label="">Αρωγή Θεσαλίας</option>
		    <option value="theotokos" label="">Θεοτόκος</option>
		    <option value="rhodes" label="">Δωδεκανήσου</option>
		  </select>
		<br>
	      </fieldset>
<!--		<input type="button" id="<?php echo $rows[4] ?>" class="upload" value="Upload video"></input>-->
	    </form>
	    </div>

	      <?php } ?>
	  </form>
	  <br><br>
	</table> 
  </div><!--END of content-->
</div><!--END of container-->

<?php showFooter(); ?><!--END of footer-->

<script>
$(document).ready(function(){
  $(".edit_tr").hover( function() {
    var id = $(this).attr('id');
    $("#del-btn-"+id).click( function() { 
      $("#"+id).hide(); 
      var dataString = 'con_id=' + id;
      $.ajax({
 	type: "POST",
 	url: "sql.php",
 	data: dataString,
 	cache: false,
 	success: function(html) {
 	}
       });
    });
  });
  // Edit Contact
  $(".edit_tr").hover(function() {
    var ID=$(this).attr('id');
     $("#edit-btn-"+ID).click(function() {
      $("#name-"+ID).hide();
      $("#phone_num_1-"+ID).hide();
      $("#phone_num_2-"+ID).hide();
      $("#mobile_num-"+ID).hide();
      $("#email-"+ID).hide();
      $("#unit-"+ID).hide();
      $("#name-input-"+ID).show();
      $("#phone_num_1-input-"+ID).show();
      $("#phone_num_2-input-"+ID).show();
      $("#mobile_num-input-"+ID).show();
      $("#email-input-"+ID).show();
      $("#unit-input-"+ID).show();
    });
   }).change(function() {
      var id=$(this).attr('id');
      var name = $("#name-input-"+id).val();
      var phone_num_1 = $("#phone_num_1-input-"+id).val();
      var phone_num_2 = $("#phone_num_2-input-"+id).val();
      var mobile_num = $("#mobile_num-input-"+id).val();
      var email = $("#email-input-"+id).val();
      var unit = $("#unit-input-"+id).val();

      var dataString = 'contact_id=' + id + '&name=' + name + '&phone_num_1=' + phone_num_1 + '&phone_num_2=' + phone_num_2 + '&mobile_num=' + mobile_num + '&email=' + email + '&unit=' + unit;
      $("#name-"+id).html('<img src="load.gif" />'); // Loading image
     
      $.ajax({
	  type: "POST",
	  url: "sql.php",
	  data: dataString,
	  cache: false,
	  success: function(html) {
	    $("#name-"+id).html(name);
	    $("#phone_num_1-"+id).html(phone_num_1);
	    $("#phone_num_2-"+id).html(phone_num_2);
	    $("#mobile_num-"+id).html(mobile_num);
	    $("#email-"+id).html(email);
	    $("#unit-"+id).html(unit);
	  }
	}); //end of ajax
    }); // end of change
	
       $(".editbox").mouseup(function() {
	return false;
      }); // end of mouseup
      // Outside click action
      $(document).mouseup(function() {
	$(".editbox").hide();
	$(".text").show();
      }); // end of mouseup
      $(document).hover(function(){
	var id=$(this).attr('id');
	$("#edit-"+id).hide();
	$("#delete-"+id).hide();
      });//end of hover

// Add new Contact
  $(".add_btn").click(function() {
    $("#dialog:ui-confirm").dialog("destroy");
    $("#dialog-confirm").dialog({
	  title: "Δώστε τα στοιχεία:",
	  resizable: false,
	  height:400,
	  width:400,
	  modal: true,
	  buttons: {
	    "OK": function() {
	      var con_name = $("#con_name").val();
	      var tel1 = $("#tel1").val();
	      var tel2= $("#tel2").val();
	      var email = $("#email").val();
	      var cell= $("#cell").val();
	      var unit= $("#unit").val();
	      var location= $("#location1").val();

	      var dataString = 'con_name='+con_name+'&tel1='+ tel1 + '&tel2=' + tel2 + '&cell=' + cell + '&email=' + email + '&unit=' + unit + '&location=' + location;

	      $.ajax({
		type: "POST",
		url: "sql.php",
		data: dataString,
		cache: false,
		success: function(html) {
		  $("#name").html(name);
		  $("#phone_num_1").html(phone_num_1);
		  $("#phone_num_2").html(phone_num_2);
		  $("#mobile_num").html(mobile_num);
		  $("#email").html(email);
		  $("#unit").html(unit);
		  $("#location1").html(location);
		}
	      });
	      $(this).dialog("close");
	    },
	    Cancel: function() {
	      $(this).dialog("close");
	    }//end of Cancel
	  }//end of buttons
	});
  });
    $("#location1").click(function() {
      if ( $("#location1").val() == "clinics" ) {
	$("#clinic").removeAttr('disabled');
      } 
      else {
	$("#clinic").attr('disabled', 'disabled');
      }
    });

// Sort table
    var table = $('.requests_table');
    $('#name, #phone_num_1, #phone_num_2, #mobile_num, #email, #location')
        .wrapInner('<span title="sort this column"/>')
        .each(function(){ 
            var th = $(this),
                thIndex = th.index(),
                inverse = false;
            th.click(function(){ 
                table.find('td').filter(function(){
                    return $(this).index() === thIndex;
                }).sortElements(function(a, b){ 
                    return $.text([a]) > $.text([b]) ?
                        inverse ? -1 : 1
                        : inverse ? 1 : -1;
                }, function(){
                    // parentNode is the element we want to move
                    return this.parentNode;      
                });              
                inverse = !inverse;     
            });               
        });

});//end of ready
</script>
</body>
</html>